﻿@model Tuple<int?>
@{
    ViewData["Title"] = "运维合同管理";
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto search" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">合同名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" id="searchBtn" lay-submit="" lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                    </button>
                    @if (1 != Model.Item1)
                    {
                        <button onclick="add()" class="layui-btn">新增</button>
                    }

                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
        </div>
    </div>
</div>



<script>



    //监听搜索
    form.on('submit(search)', function (data) {
        var field = data.field;
        //执行重载
        table.reload('LAY-app-content-list', {
            where: field
        });
    });


    //加载table
    var tableObj = table.render({
        elem: '#LAY-app-content-list'
        , url: '/serviceContract/list' //模拟接口
        , page: true
        , height:'full-110'
        , cols: [[
            {
                field: 'title', title: '名称', minWidth: 100, templet: '<div><a class="link" onclick="showDetail(\'{{d.id}}\')">{{ d.title }}</a></div>' }
            , { field: 'deviceType', title: '设备类型', width: 100, templet: '<div>{{ d.deviceType.name}}</div>' }
            , { field: 'amount', style: 'text-align:center;padding-right:0px;',title: '合同金额', width: 90, templet: '<div>{{ d.amount}}</div>' }
            , { field: 'boss', title: '甲方', width: 120, templet: '<div>{{ d.boss}}</div>' }
            , { field: 'employee', title: '乙方', width: 120, templet: '<div>{{ d.employee}}</div>' }
            , { field: 'startDate', title: '合同时间', width: 150, templet: '<div>{{ d.startDate.substring(0,10)}}</div>' }
            , { field: 'endDate', title: '到期时间', width: 150, templet: '<div>{{ d.endDate.substring(0,10) }}</div>' }
            , {
                field: 'opr', title: '操作', width: 150, fixed: 'right',
                templet: '<div class="layui-table-cell laytable-cell-11-0-8"> <a class="layui-btn layui-btn-normal layui-btn-xs"  onclick="edit(\'{{ d.id }}\')" ><i class="layui-icon layui-icon-edit"></i>编辑</a>  <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="deleteItem(\'{{ d.id }}\')"><i class="layui-icon layui-icon-delete"></i>删除</a> </div>'
            }
            ]]
            , skin: 'line'
     });

    //新增合同
    function add() {
        winIndex = layer.open({
            type: 2,
            title: '新增',
            content: '/serviceContract/edit',
            area: ["1100px", "550px"]
        });

    }

    function edit(id) {
        winIndex = layer.open({
            type: 2,
            title: '编辑',
            content: '/serviceContract/edit?id=' + id,
            area: ["1100px", "550px"]
        });
    }


    function deleteItem(id) {
        layer.confirm("确定要删除吗？", function (index) {
            layer.close(index);
            $.post("/serviceContract/delete?id=" + id, function (d) {
                layer.msg(d.msg);
                if (d.code == 1) {
                    tableObj.reload();
                }
            });
        });
    }


    function showDetail(id) {
        window.top.layer.open({
            type: 2,
            title: '查看',
            content: '/serviceContract/detail?id=' + id,
            area: ["1100px", "550px"]
        });
    }


    $(document).on('keydown', function (e) {
        if (e.keyCode == 13) {
            $("#searchBtn").click();
        }
    })
</script>

